<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/activityGrouping.css" rel="stylesheet" type="text/css" />
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <style type="text/css">
      .react-film__flipper {
        /* Hide flipper because they are not part of the tests and introduce reliability issues due to its animation. */
        display: none;
      }
    </style>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="text/babel" data-presets="env,stage-3,react">
      const {
        React: { useContext, useEffect, useMemo },
        ReactDOM: { render },
        testHelpers: {
          activityGrouping: {
            ActivityGroupingBadges,
            ActivityGroupingContext,
            ActivityGroupingPanel,
            ActivityGroupingSurface,
            customAdaptiveCardsHostConfig
          }
        },
        WebChat: {
          Components: { BasicWebChat, Composer }
        }
      } = window;

      run(async function () {
        const params = new URLSearchParams(location.hash.replace(/^#/u, ''));

        const height = params.get('ch');
        const width = params.get('cw');

        await host.windowSize(width, height, document.getElementById('webchat'));

        const TestHarness = () => {
          const { activityMiddleware, directLine, rtl, styleOptions, wide } = useContext(ActivityGroupingContext);
          const store = useMemo(() => testHelpers.createStore());

          return (
            <div className={classNames('test-harness', { 'test-harness--wide': wide })} dir={rtl ? 'rtl' : 'ltr'}>
              {!!directLine && (
                <Composer
                  activityMiddleware={activityMiddleware}
                  adaptiveCardsHostConfig={customAdaptiveCardsHostConfig}
                  directLine={directLine}
                  dir={rtl ? 'rtl' : undefined}
                  store={store}
                  styleOptions={styleOptions}
                >
                  <BasicWebChat className="webchat" />
                  <ActivityGroupingBadges />
                  <ActivityGroupingPanel />
                </Composer>
              )}
            </div>
          );
        };

        render(
          <ActivityGroupingSurface>
            <TestHarness />
          </ActivityGroupingSurface>,
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();
        await pageConditions.allImagesLoaded();
        await pageConditions.scrollToBottomCompleted();

        await host.snapshot('local');
      });
    </script>
  </body>
</html>
